return function()
  require('mason-null-ls').setup({
    ensure_installed = { 'stylua', 'rustfmt', 'clang_format' },
  })
  local nls = require('null-ls')
  local formatting = nls.builtins.formatting
  local diagnostics = nls.builtins.diagnostics
  local completion = nls.builtins.completion
  local augroup = vim.api.nvim_create_augroup('LspFormatting', {})
  -- 指定格式化lsp为
  local lsp_formatting = function(bufnr)
    vim.lsp.buf.format({
      filter = function(client)
        return client.name == 'null-ls'
      end,
      bufnr = bufnr,
    })
  end
  -- 具体配置
  nls.setup({
    ensure_installed = { 'stylua', 'rustfmt', 'clang_format' },
    debug = false,
    root_dir = require('null-ls.utils').root_pattern('.null-ls-root', '.neoconf.json', 'Makefile', '.git'),
    sources = {
      formatting.clang_format,
      formatting.rustfmt,
      formatting.stylua,
      diagnostics.eslint,
      completion.spell,
    },
    on_attach = function(client, bufnr)
      -- 禁用lsp的格式化，采用专门的插件格式化
      client.server_capabilities.document_formatting = false
      client.server_capabilities.document_range_formatting = false
      -- 格式化快捷键
      vim.keymap.set(
        'n',
        '<leader>f',
        lsp_formatting,
        { desc = 'Format current buffer', noremap = true, silent = true, buffer = bufnr }
      )
      -- 保存时自动格式化
      if client.supports_method('textDocument/formatting') then
        vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
        vim.api.nvim_create_autocmd('BufWritePre', {
          group = augroup,
          buffer = bufnr,
          callback = function()
            lsp_formatting(bufnr)
          end,
        })
      end
    end,
  })
end
